package com.dhcc.sdc.cdss.controller;


import java.util.List;
import java.util.Map;


import com.dhcc.sdc.cdss.entity.SdcCdssItemLogEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssItemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sdc.cdss.entity.SdcCdssItemEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssItemService;


/**
 * CDSS推荐方案项目
 * 
 * @ClassName: SdcCdssItemController
 * @Description: TODO
 * @author sunyingjie
 * @date 2023-01-03 14:23:49
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdccdssitem")
public class SdcCdssItemController extends BaseController {

	private String PREFIX = "/backend/cdss/sdccdssitem/";

	@Autowired
	private ISdcCdssItemService sdcCdssItemService;
    @Autowired
	private ISdcCdssItemLogService sdcCdssItemLogService;
	

    /**
     * 跳转到CDSS推荐方案项目列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdccdssitem.html";
    }
	
    /**
     * 跳转到新增CDSS推荐方案项目
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdccdssitem_add.html";
    }
	
	/**
     * 跳转到修改CDSS推荐方案项目
     */
    @RequestMapping("/to_update/{sdcCdssItemId}")
    public String toUpdate(@PathVariable Integer sdcCdssItemId, Model model) {
        SdcCdssItemEntity sdcCdssItem = this.sdcCdssItemService.selectById(sdcCdssItemId);
        model.addAttribute("sdcCdssItem",sdcCdssItem);
        return PREFIX + "sdccdssitem_edit.html";
    }

    /**
     * 获取CDSS推荐方案项目列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcCdssItemEntity> page = new PageFactory<SdcCdssItemEntity>().defaultPage();
        List<SdcCdssItemEntity> result = this.sdcCdssItemService.page(page,params);
        page.setRecords((List<SdcCdssItemEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增CDSS推荐方案项目
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssItemEntity sdcCdssItem) {
        if (CommonUtil.isOneEmpty(sdcCdssItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemService.insert(sdcCdssItem);
        return R.ok();
    }

    /**
     * 删除CDSS推荐方案项目
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sdcCdssItemId) {
	
        this.sdcCdssItemService.deleteById(sdcCdssItemId);

        return R.ok();
    }

    /**
     * 修改CDSS推荐方案项目
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssItemEntity sdcCdssItem) {
        if (CommonUtil.isOneEmpty(sdcCdssItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemService.updateById(sdcCdssItem);
        return R.ok();
    }


    @RequestMapping("/logList")
    @ResponseBody
    public Object logList(@RequestParam Map<String, Object> params) {
        Page<SdcCdssItemLogEntity> page = new PageFactory<SdcCdssItemLogEntity>().defaultPage();
        List<SdcCdssItemLogEntity> result = sdcCdssItemLogService.page(page, params);
        page.setRecords((List<SdcCdssItemLogEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }
	
}
